package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ModuleVolumeInfoPreview;
import com.ruoyi.system.service.IModuleVolumeInfoPreviewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案卷导入预览Controller
 *
 * @author ruoyi
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/system/volumePreview")
public class ModuleVolumeInfoPreviewController extends BaseController {
    @Autowired
    private IModuleVolumeInfoPreviewService moduleVolumeInfoPreviewService;

    /**
     * 查询案卷导入预览列表
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModuleVolumeInfoPreview moduleVolumeInfoPreview) {
        startPage();
        PageHelper.orderBy("index_id");
        List<ModuleVolumeInfoPreview> list = moduleVolumeInfoPreviewService
                .selectModuleVolumeInfoPreviewList(moduleVolumeInfoPreview);
        return getDataTable(list);
    }

    /**
     * 导出案卷导入预览列表
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:export')")
    @Log(title = "案卷导入预览", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModuleVolumeInfoPreview moduleVolumeInfoPreview) {
        List<ModuleVolumeInfoPreview> list = moduleVolumeInfoPreviewService
                .selectModuleVolumeInfoPreviewList(moduleVolumeInfoPreview);
        ExcelUtil<ModuleVolumeInfoPreview> util = new ExcelUtil<ModuleVolumeInfoPreview>(ModuleVolumeInfoPreview.class);
        util.exportExcel(response, list, "案卷导入预览数据");
    }

    /**
     * 获取案卷导入预览详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(moduleVolumeInfoPreviewService.selectModuleVolumeInfoPreviewById(id));
    }

    /**
     * 新增案卷导入预览
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:add')")
    @Log(title = "案卷导入预览", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ModuleVolumeInfoPreview moduleVolumeInfoPreview) {
        return toAjax(moduleVolumeInfoPreviewService.insertModuleVolumeInfoPreview(moduleVolumeInfoPreview));
    }

    /**
     * 修改案卷导入预览
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:edit')")
    @Log(title = "案卷导入预览", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ModuleVolumeInfoPreview moduleVolumeInfoPreview) {
        return toAjax(moduleVolumeInfoPreviewService.updateModuleVolumeInfoPreview(moduleVolumeInfoPreview));
    }

    /**
     * 删除案卷导入预览
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:remove')")
    @Log(title = "案卷导入预览", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(moduleVolumeInfoPreviewService.deleteModuleVolumeInfoPreviewByIds(ids));
    }
}
